<!-- 活动跨会合作联系人配置 -->
<template>
  <a-modal
    v-model="visible"
    title="合作联系人"
    destroyOnClose
    :maskClosable="false"
    centered
    :width="600"
    okText="确定修改"
    @ok="handleOk"
  >
    <a-form-model ref="form" :model="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }">
      <a-form-model-item label="跨会合作联系人" extra="本联系方式将会展示给协办组织">
        <a-select
          v-model="form.activityContactJoinUnion.sysUserId"
          placeholder="请选择合作联系人"
          @change="contactChange"
        >
          <a-select-option v-for="item in attache_list" :key="item.userId" :value="item.userId">
            {{ item.userName }}
          </a-select-option>
        </a-select>
      </a-form-model-item>
    </a-form-model>
  </a-modal>
</template>

<script>
import { getUserList } from '@/api/system/system'
import { editSection } from '@/api/activity/activity';
import { cloneDeep } from 'lodash-es'

export default {
  data() {
    return {
      visible: false,
      attache_list: [],
      form: {
        activityContactJoinUnion: {
          id: undefined,
          sysUserId: undefined,
          name: undefined,
          phone: undefined
        }
      }
    }
  },
  methods: {
    openModal(activityInfo){
      this.geAdminList()
      this.form = cloneDeep(activityInfo);
      this.form.activityContactJoinUnion = this.form.activityContactJoinUnion || { sysUserId: undefined }
      this.visible = true
    },
    // 获取跨会合作联系人
    geAdminList() {
      getUserList().then(res => {
        this.attache_list = res.rows || []
      })
    },
    contactChange(val) {
      let item = this.attache_list.find(f => f.userId === val)
      this.$set(this.form.activityContactJoinUnion, 'name', item.userName)
      this.$set(this.form.activityContactJoinUnion, 'phone', item.phonenumber)
    },
    handleOk() {
      console.log(this.form);
      editSection(this.form).then(res=>{
        this.$message.success('修改成功')
        this.visible = false
        this.$emit('refresh')
      })
    }
  }
}
</script>

<style lang="scss" scoped>

</style>